package pe.edu.pucp.cpnc.mm.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement
//Indicamos en que orden queremos que imprima los atributos
@XmlType(propOrder ={"id","name","color","civilization","type","objectDetails"})
public class Player implements Serializable{
	private int id;
	private int color;
	private int type; // 0 is Player, 1 is Computer, 2 is Neutral
	private String civilization;//Assuming there are races or factions within the game.
	private String name;
	private ArrayList<ObjectDetail> objectDetails;
	
	public Player(){
		objectDetails=new ArrayList<>();
	}
	
	public Player(int id, int color, int type, String civilization, String name){
		this.id = id;
		this.color = color;
		this.civilization = civilization;
		this.name = name;
		objectDetails = new ArrayList<>();
	}
        
        public Player(Player p, HashMap<String, ObjectDetail> objDetMap){
            id = p.id;
            color = p.color;
            type = p.type;
            civilization = p.civilization;
            name = p.name;
            objectDetails = new ArrayList<>();
            for(ObjectDetail objDet : p.objectDetails ){
                ObjectDetail copyObjDet = new ObjectDetail(objDet);
                objectDetails.add(copyObjDet);
                objDetMap.put(copyObjDet.getId(), copyObjDet);
            }
        }
	
	public int getId() {
		return id;
	}
	@XmlAttribute
	public void setId(int id) {
		this.id = id;
	}
	public int getColor() {
		return color;
	}
	public void setColor(int color) {
		this.color = color;
	}
	public int getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}
	public String getCivilization() {
		return civilization;
	}
	public void setCivilization(String civilization) {
		this.civilization = civilization;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	//Establecemos un wrapper para la coleccion de los detalles de objeto
		@XmlElementWrapper(name = "objectDetailList")
		@XmlElement(name = "objectDetail")
	public ArrayList<ObjectDetail> getObjectDetails() {
		return objectDetails;
	}
	public void setObjectDetails(ArrayList<ObjectDetail> objectDetails) {
		this.objectDetails = objectDetails;
	}
	
        @Override
        public String toString(){
            return this.name;
        }
		
}
